using System;
using Pine.Core;
using Pine.SourceParser.Tree;

namespace Pine.CodeGen
{
	public static class ExpressionStatementCodeGenerator
	{
		public static void GenerateBytecode(Context ctx, Statement stmt)
		{
			ExpressionStatement e = (ExpressionStatement) stmt;
			
			UnaryExpression ue = e.e as UnaryExpression;
			
			if (!(ue != null && (ue.type == UnaryExpressionType.Increment || ue.type == UnaryExpressionType.Decrement))
			    && !(e.e is CallExpression) && !(e.e is PostfixExpression))
			{
				throw new Exception("Useless statement : " + e);
			}
			
			e.e.GenerateBytecode(ctx, ctx.il.DeclareLocal(typeof(Value)));
		}
	}
}

